package com.shitou.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.shitou.dao.AssignmentDao;
import com.shitou.pojo.Assignment;
import com.shitou.pojo.User;
import com.shitou.util.DateUtil;

@Service
@Transactional
public class AssignmentService {

	@Resource
	private AssignmentDao dao;

	
	
	public Assignment save(Assignment assignment) {
		assignment.setUpdatedate(DateUtil.getNow());
		dao.save(assignment);
		return assignment;
	}

	public Assignment findById(int id) {
		return dao.findById(id);
	}

	public List<Assignment> findByState(int state) {
		String hql = "from Assignment where state = ?";
		return dao.findListByHQL(hql, state);
	}

	public List<Assignment> findByUser(User u) {
		String hql = "from Assignment where userid = ?";
		return dao.findListByHQL(hql, u.getId());
	}
	
}
